import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class BinarySearchTreeTest {
    public static void main(String[] args) {
        BinarySearchTree<Integer> tree = new BinarySearchTree<>();
        tree.insert(8);
        tree.insert(12);
        tree.insert(5);
        tree.insert(6);
        tree.insert(11);
        tree.insert(15);
        tree.insert(4);
        tree.insert(14);
        List<List<BinarySearchTree<Integer>.Node<Integer>>> levels = tree.orderLevel();
        levels.forEach(list->{
            list.forEach(node-> System.out.print(node.val+"\t"));
            System.out.println();
        });
        System.out.println("-----------search--------------------");
        AtomicInteger searchDeep = new AtomicInteger(0);
        tree.search(5, searchDeep);
        System.out.println("搜索5比较次数为："+searchDeep.get());
        System.out.println("-----------remove--------------------");
        tree.remove(12);
        levels = tree.orderLevel();
        levels.forEach(list->{
            list.forEach(node-> System.out.print(node.val+"\t"));
            System.out.println();
        });

    }
}
